package fr.umlv.m2.recipes.ideas.services;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

/**
 * Create a service to synchronize a external database
 * @author Younes Chandarli et Christophe Chillan 
 *
 */
public class SyncService extends Service{

	private final IBinder mBinder = new LocalBinder();
	/**
	 * Create a {@link Binder}
	 * @author Younes Chandarli
	 *
	 */
	public class LocalBinder extends Binder {
		SyncService getService() {
            return SyncService.this;
        }
    }
	
	@Override
	public IBinder onBind(Intent intent) {
		return mBinder;
	}

	private Timer timer ; 
	 
	@Override 
	public void onCreate() { 
	    super.onCreate(); 
	    timer = new Timer(); 
	    Log.e(this.getClass().getName(), "--------------onCreate");
	    
	} 
	 
	@Override 
	public int onStartCommand(Intent intent, int flags, int startId) { 
	    Log.e(this.getClass().getName(), "-------------------onStart"); 
	    timer.scheduleAtFixedRate(new TimerTask() { 
	        public void run() { 
	        	 Log.e(this.getClass().getName(), "-------------------timer"); 
	        } 
	    }, 0, 60000); 
	    return START_NOT_STICKY; 
	} 
	 
	@Override 
	public void onDestroy() { 
	    Log.e(this.getClass().getName(), "-------------onDestroy"); 
	    this.timer.cancel(); 
	} 
}
